package com.finger.forest;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.finger.forest.base.BaseActivity;
import com.finger.forest.base.BaseView;
import com.finger.forest.base.CommonKey;
import com.finger.forest.base.ResponseTag;
import com.finger.forest.http.presenter.RegisterPresenter;
import com.finger.forest.model.GridUserModel;
import com.finger.forest.model.MobileUserModel;
import com.finger.forest.utils.ClickUtils;
import com.finger.forest.utils.StringUtil;
import com.finger.forest.utils.encode.PrefsUtil;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 设置
 */
public class SettingActivity extends BaseActivity<RegisterPresenter> implements BaseView {

    /**
     * 返回
     */
    @BindView(R.id.btn_back)
    ImageView backIv;

    /**
     * 退出登录
     */
    @BindView(R.id.layout_logout)
    LinearLayout logoutLayout;

    /**
     * 联系人
     */
    @BindView(R.id.layout_contact)
    LinearLayout contactLayout;

    /**
     * 昵称
     */
    @BindView(R.id.tv_user_name)
    TextView userNameTv;

    /**
     * 密码
     */
    @BindView(R.id.tv_user_password)
    TextView userPasswordTv;

    /**
     * 手机号
     */
    @BindView(R.id.tv_user_cellphone)
    TextView userCellphoneTv;

    @Override
    protected int setView() {
        return R.layout.activity_setting;
    }

    @Override
    protected void receiveData() {

    }

    @Override
    protected void initializeView() {
        String userId = PrefsUtil.getString(this, CommonKey.USER_ID);
        Map<String, Object> maps = new HashMap<>();
        maps.put("userId",userId);
        presenter.getUserDetail(maps);
    }

    @Override
    protected void loadDataFromServer() {

    }

    @OnClick({R.id.btn_back, R.id.layout_logout, R.id.layout_contact })
    public void onClick(View v) {
        if (ClickUtils.isFastClick()) { //防止重复点击
            switch (v.getId()) {

                //返回
                case R.id.btn_back:
                    finish();
                    break;

                //联系人
                case R.id.layout_contact:
                    Intent intentContact = new Intent(SettingActivity.this,ContactActivity.class);
                    startActivity(intentContact);
                    break;

                //退出登录
                case R.id.layout_logout:
                    Intent intent = new Intent(SettingActivity.this,LoginActivity.class);
                    startActivity(intent);
                    break;

                default:
                    break;
            }
        }
    }

    @Override
    public void onSuccess(Object model, int tag, String msg) {

        switch (tag) {

            //个人详情
            case ResponseTag.GET_USER_DETAIL:
                GridUserModel userModel = (GridUserModel) model;
                userNameTv.setText(userModel.getName());
                userPasswordTv.setText(userModel.getPassword());
                userCellphoneTv.setText(userModel.getCellphone());
                break;

            default:
                break;
        }
    }

    @Override
    public void onError(int errcode, int tag, String message) {

    }
}
